<template>
  <div style="height: 100%;">
    <x-header :left-options="{preventGoBack:true,backText: ''}"
              @on-click-back="backhome">安全教育早会填写</x-header>
    <div class="main-container">
      <!-- <div id="map"></div> -->
      <v-touch v-on:swiperight="onSwipeRight"
               :swipe-options="{direction: 'horizontal'}">
        <div>
          <group>
            <cell title="项目部"
                  v-model="sysPrjName"
                  is-link
                  link="prjListS"></cell>
            <cell title="工程项目"
                  v-model="projectName"
                  is-link
                  link="prjListS"></cell>  

           <group > 
             <div class="cell_style" >
             <person-tree 
                         title="带班人"
                         v-model="dutyperson"
                         ></person-tree></div></group>
                         

            <x-input title="参与人"
                     v-model="participants"
                     text-align=right
                     placeholder="请填写"
                     ></x-input>
            </group>

          <group title="早会视频">
            <picture-upload :pageToken="pageToken"
                            v-model="attachments"
                            type="VIDEO"></picture-upload>
                            
          </group>

          <group title="备注">
            <x-textarea placeholder="请输入备注，非必填"
                        v-model="remarks"></x-textarea>
                        
          </group>

          <group >
            <calendar v-model="date"
                      title="早会日期"
                      disable-future
                      ></calendar>
            <cell title="填写人"
                  v-model="inputUserFullName"></cell>
            <cell title="联系电话"
                  v-model="mobile"></cell>
            <cell title="填写部门"
                  v-model="inputUserDeptName"></cell>
            <cell title="填写时间"
                  v-model="inputDate"></cell>
          </group>       
          <div style="text-align:center;display:flex" class="top-border">
            <button class="userBack-button_save" @click="saveInspectionInfo">保存</button>
            <Toast :value="toastValue"
                   :is-show-mask="true"
                   text="保存成功"
                   @on-hide="saveSuccess"></Toast>
            <Toast :value="toastValueErr"
                   :is-show-mask="true"
                   :text="err"
                   @on-hide="saveErr"
                   type="cancel"
                   width="200px"></Toast>
          </div>
        </div>
      </v-touch>
    </div>
  </div>
</template>
 
<script>
import * as L from "leaflet";
//Vue.L = Vue.prototype.$L = L
import {
  Group,
  Cell,
  XButton,
  Box,
  GroupTitle,
  Flexbox,
  FlexboxItem,
  Divider,
  Calendar,
  PopupPicker,
  Toast,
  XInput,
  Picker
} from "vux";
import { createSecretKey } from 'crypto';
var map = null;
var marker = null;
var flag = 0;
export default {
  components: {
    XButton,
    Box,
    GroupTitle,
    Group,
    Flexbox,
    FlexboxItem,
    Divider,
    Group,
    Cell,
    Calendar,
    PopupPicker,
    Toast,
    XInput,
    Picker
  },
  name: "HelloWorld",
  data () {
    return {
      sysprjID:this.$route.query.sysprjID,
      sysPrjName: this.$route.query.sysPrjName,
      projectName: this.$route.query.projectName,
      projectName1:this.$route.query.sysPrjName === "无"?"":this.$route.query.projectName,
      projectId: this.$route.query.projectId,
      inputUserFullName: this.$store.state.user.ADUSER_NAME,
      userName: this.$store.state.user.loginId,
      mobile: this.$store.state.user.mobil,
      inputUserDeptName: this.$store.state.user.orgName,
      inputUserDeptId: this.$store.state.user.orgId,
      title:"",
      DESCRIPTION: "",
      pageToken: "",
      attachments: "",
      dutyperson:"",
      participants:"",
      buttonid: "",
      inputDate: "",
      remarks:"",
      date:"",
      month: "",
      year: "",
      toastValue: false,
      toastValueErr: false,
      err: ""
    };
  },
  methods: {
  clear(){
    debugger;
    this.participants = "";
  },
    onSwipeRight () {
      this.$router.push("/safetyMeetingList");
    },


    backhome () {
        this.$router.push({ path: "/safetyMeetingList", query: {   } });
    },
    saveInspectionInfo () {
      this.err = "";
      if (!this.projectName) {
        this.err += "【工程项目】不能为空<br/>";
      }
     
      if (this.dutyperson == "") {
        this.err += "【带班人】不能为空<br/>";
      }
      if (this.participants == "") {
        this.err += "【参与人】不能为空<br/>";
      }
      if (this.attachments == "") {
        this.err += "【上传录像】不能为空<br/>";
      }
      if (this.date == "") {
        this.err += "【日期】不能为空<br/>";
      }
      //   if (this.unitName == '') {
      //     this.err += '【单位工程】不能为空<br/>'
      //   }
      if (this.err != "") {
        this.toastValueErr = true;
        return false;
      }

                 
         var params = {
           _method: "formService.saveFormData",
           requestEventData: {
            eventType: "formSubmitEvent",
            formType: 1,
            bizObjId: "PMMOBILE_DANGEREDUCATION",
            formId: "PMMOBILE_DANGEREDUCATION_ADD",
            buttonId: this.buttonid
          },
            _OBJ_NAME_: "PMMOBILE_DANGEREDUCATION",
            _FORM_ID_: "PMMOBILE_DANGEREDUCATION_ADD",
            useType: "add",
            pageToken: this.pageToken,
            formData: {
            objName: "PMMOBILE_DANGEREDUCATION",
            pks: ["GUID"],
            data: [
              {
                rowData: [
                  {
                    DataTarget: "GUID",
                    Value: "",
                    OriginalValue: null,
                    PK: true,
                    DataType: "String"
                  },
                  {
                    DataTarget:"TITLE",
                    Value:this.projectName+"在"+this.inputDate+"举行的教育早会",
                    OriginalValue:null,
                    PK:false,
                    DataType:"String"
                  },
                  {
                    DataTarget: "SYSPRJID",
                    Value: this.sysprjID,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "SYSPRJNAME",
                    Value: this.sysPrjName,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "PROJECTID",
                    Value: this.projectId,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "PROJECTNAME",
                    Value: this.projectName,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "PROJECTNAME1",
                    Value: this.projectName1,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "DUTYPERSON",
                    Value: this.dutyperson,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "DUTYPERSONID",
                    Value:"",
                    OriginalValue:null,
                    PK:false,
                    DataType:"String"
                  },
                  {
                    DataTarget: "PARTICIPANTS",
                    Value: this.participants,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "ATTACHMENTS",
                    Value: this.attachments,
                    OriginalValue: null,
                    PK: false,
                    DataType: "Store.ecidiDoc"
                  },
                
                  {
                    DataTarget: "DATE",
                    Value: this.date ,
                    OriginalValue: null,
                    PK: false,
                    DataType: "TimeStamp"
                  },
                  {
                    DataTarget: "INPUTUSERNAME",
                    Value: this.userName,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },                 
                  {
                    DataTarget: "INPUTUSERFULLNAME",
                    Value: this.inputUserFullName,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },      
                   {
                    DataTarget: "INPUTUSERDEPTNAME",
                    Value: this.inputUserDeptName,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "INPUTUSERDEPTID",
                    Value: this.inputUserDeptId,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget: "INPUTDATE",
                    Value: this.inputDate,
                    OriginalValue: null,
                    PK: false,
                    DataType: "TimeStamp"
                  },            
                  {
                    DataTarget: "MOBILE",
                    Value: this.mobile,
                    OriginalValue: null,
                    PK: false,
                    DataType: "String"
                  },
                  {
                    DataTarget:"PROJECTNAME1",
                    Value:this.projectName1,
                    OriginalValue:null,
                    PK:false,
                    DataType:"String"
                 },
                  {
                    DataTarget:"REMARKS",
                    Value:this.remarks,
                    OriginalValue:null,
                    PK:false,
                    DataType:"String"
                  }
              
                ],
                children: []
              }
            ]
          },
          _ATTACHMENT_DELETE_IDS_: "",
          formInfo: {
            GUID: "",
            SYSPRJID:this.sysprjID,
            SYSPRJNAME: this.sysPrjName,
            PROJECTID: this.projectId,
            PROJECTNAME:this.projectName,
            DUTYPERSON: this.dutyperson,
            PARTICIPANTS: this.participants,
            ATTACHMENTS: this.attachments,
            DATE: this.date ,
            INPUTUSERNAME: this.userName,
            INPUTUSERFULLNAME: this.inputUserFullName,
            INPUTUSERDEPTNAME: this.inputUserDeptName,
            INPUTUSERDEPTPATHID: this.inputUserDeptId,
            INPUTDATE: this.inputDate + " 00:00:00.000",
            MOBILE: this.mobile,
          }
        };
        let json = {
          FixJSON: JSON.stringify(params)
        };
        this.$ajax({
          url: this.COMMON_URL,// + "?_viewId=PMMOBILE_DANGEREDUCATION_ADD",
          method: "post",
          // data: this.signMD5(json)
          data:json
        })
          .then(res => {
            this.toastValue = true;
          })
          .catch(err => {
            alert(err);
          });

    },

    saveSuccess () {
      this.backhome();
    },
    saveErr () {
      this.toastValueErr = false;
    },
    // 设置默认时间
    setDefautlDate () {
      let now = new Date();
      let month = now.getMonth() + 1;
      let day = now.getDate();
      // let hour = now.getHours();
      // let min = now.getMinutes();
      // let sec = now.getSeconds();
      if (month < 10) {
        month = '0' + month
      }
      if (day < 10) {
        day = "0" + day
      }
      // if(hour < 10) {
      //   hour = "0" + hour
      // }
      // if(min < 10){
      //           min = "0" + min
      //       }
      // if(sec < 10){
      //           sec = "0" + sec
      //       }            
     
      this.inputDate = now.getFullYear() + "-" + month + "-" + day;
    }    
  },
  mounted () {
    this.setDefautlDate();

    var greenIcon = L.icon({
      iconUrl: "../src/assets/img/sign-in.png",
      iconSize: [26, 44], // size of the icon
      iconAnchor: [17, 48] // point of the icon which will correspond to marker's location
      //popupAnchor:  [-3, -76] // point from which the popup should open relative to the iconAnchor
    });
    this.pageToken = this.guid(); //this.sPageToken();
    // this.fieldToken = this.guid();
    this.buttonid = this.guid();

    
  },
  watch: {

  }
};
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
/* .transition-view /deep/.weui-cells__title {
      margin-top: 0.77em;
    margin-bottom: 0.3em;
    padding-left: 15px;
    padding-right: 15px;
    color: #353535;
    font-size: 14px;
} */
/* .transition-view /deep/ .vux-header .vux-header-left .left-arrow:before {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border: 1px solid rgba(0, 0, 0, 0.8);
  border-width: 1px 0 0 1px;
  -webkit-transform: rotate(315deg);
  transform: rotate(315deg);
  top: 8px;
  left: 7px;
} */
/* .transition-view /deep/ .vux-header .vux-header-title {
  line-height: 40px;
  text-align: center;
  font-size: 18px;
  font-weight: 400;
  color: #333;
} */
.top-border{
  border-top: 1px solid #f5f5f5
}
.userBack-button_save{
      width: 60%;
      height: 40px;
      background-color: #4D86FF; 
      border-radius: 2pt;
      border: 1pt solid #4D86FF;
      margin-top: 20pt;
      color: #FFFFFF;
      font-size: 15px;
      margin-right: auto;
      margin-left: auto;
      margin-bottom: 20pt;
}

.cell_style{
  min-height: 38px;
   font-size: 17px;
}

#map {
  width: 100%;
  height: 25%;
}
.content {
  width: 100%;
  height: 75%;
}
</style>